function insertSort(arr) {
    for(let i = 1; i < arr.length; i++) {
        let j = i - 1;
        let key = arr[i]
        while(j >= 0 && arr[j] > key) {
            arr[j + 1] = arr[j]
            j--
        }
        arr[j + 1] = key
    }
}
let arr = [2, 1, 5, 9, 4, 3, 3, 1]
insertSort(arr)
console.log(arr);